home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / misc / linuxconf.c < prev    next >
C/C++ Source or Header  |  1996-07-20  |  3KB  |  148 lines

  1. #include <stdio.h>
  2. #include <errno.h>
  3. #include <string.h>
  4. #include "misc.h"
  5. #include "confdb.h"
  6. #include "../paths.h"
  7.  
  8. /* #Specification: /etc/conf.linuxconf / permissions
  9.     For security reasons, /etc/conf.linuxconf is unreadable for all
  10.     users except root. There is a lot of information in it allowing
  11.     potential intruders to spot information that they really don't need to
  12.     know.
  13.  
  14.     For exemple, /etc/conf.linuxconf tells which users have which
  15.     administrative privilege. This is not much for an intruder, but it
  16.     certainly tells which user passwords have move value than others.
  17. */
  18. static HELP_FILE helpf ("misc","linuxconf");
  19.  
  20. static CONFIG_FILE f_linuxconf (ETC_CONF_LINUXCONF
  21.     ,helpf
  22.     ,CONFIGF_OPTIONNAL|CONFIGF_MANAGED
  23.     ,"root","root",0600);
  24.  
  25.  
  26.  
  27. static CONFDB *tb = NULL;
  28.  
  29. static void linuxconf_init()
  30. {
  31.     if (tb == NULL) tb = new CONFDB (f_linuxconf);
  32. }
  33.  
  34. /*
  35.     Locate one configuration parameter.
  36.     Return NULL if not found.
  37. */
  38. const char *linuxconf_getval (const char *prefix, const char *key)
  39. {
  40.     linuxconf_init();
  41.     return tb->getval (prefix,key);
  42. }
  43. /*
  44.     Locate one numeric configuration parameter.
  45.     Return defval if not found.
  46. */
  47. int linuxconf_getvalnum (const char *prefix, const char *key, int defval)
  48. {
  49.     linuxconf_init();
  50.     return tb->getvalnum(prefix,key,defval);
  51. }
  52.  
  53. /*
  54.     Locate all configuration parameter with the same key.
  55.     Return the number found.
  56. */
  57. int linuxconf_getall (
  58.     const char *prefix,
  59.     const char *key,
  60.     SSTRINGS &lst,
  61.     int copy)    // Take a copy of the values
  62. {
  63.     linuxconf_init();
  64.     return tb->getall (prefix,key,lst,copy);
  65. }
  66.  
  67. /*
  68.     Remove all entry with a given key.
  69. */
  70. void linuxconf_removeall (const char *prefix, const char *key)
  71. {
  72.     if (tb != NULL) tb->removeall (prefix,key);
  73. }
  74.  
  75. /*
  76.     Save the configuration parameters
  77.     Return -1 if any error.
  78. */
  79. int linuxconf_save()
  80. {
  81.     int ret = 0;
  82.     if (tb != NULL){
  83.         ret = tb->save();
  84.         if (ret == -1 && errno == EPERM){
  85.             // Avoid keeping in memory records potentially entered
  86.             // by a user who don't know the root password.
  87.             delete tb;
  88.             tb = NULL;
  89.         }
  90.     }
  91.     return ret;
  92. }
  93.  
  94. /*
  95.     Add one record to the configuration file
  96. */
  97. void linuxconf_add (const char *prefix, const char *key, const char *val)
  98. {
  99.     linuxconf_init();
  100.     tb->add (prefix,key,val);
  101. }
  102. /*
  103.     Add one record in the configuration file
  104. */
  105. void linuxconf_add (const char *prefix, const char *key, const SSTRING &val)
  106. {
  107.     linuxconf_init();
  108.     tb->add (prefix,key,val);
  109. }
  110. /*
  111.     Replace one record in the configuration file
  112. */
  113. void linuxconf_replace (const char *prefix, const char *key, const char *val)
  114. {
  115.     linuxconf_init();
  116.     tb->replace (prefix,key,val);
  117. }
  118. /*
  119.     Replace one record in the configuration file
  120. */
  121. void linuxconf_replace (const char *prefix, const char *key, int val)
  122. {
  123.     linuxconf_init();
  124.     tb->replace (prefix,key,val);
  125. }
  126. /*
  127.     Replace one record in the configuration file
  128. */
  129. void linuxconf_replace (const char *prefix, const char *key, const SSTRING &val)
  130. {
  131.     linuxconf_init();
  132.     tb->replace (prefix,key,val);
  133. }
  134.  
  135. /*
  136.     Replace all records to the configuration file for a key
  137. */
  138. void linuxconf_replace (
  139.     const char *prefix,
  140.     const char *key,
  141.     const SSTRINGS &vals)
  142. {
  143.     linuxconf_init();
  144.     tb->replace (prefix,key,vals);
  145. }
  146.  
  147.  
  148.